Skip to content

Conversation

@chlowell
Copy link
Member

@chlowell chlowell commented Apr 29, 2021

When its on_challenge method is not overridden, the ChallengeAuthenticationPolicy proposed in #17489 is functionally equivalent to the existing BearerTokenCredentialPolicy. It's reasonable then to wonder how the existing policy would look when extended to handle authentication challenges. Short answer: it would look something like this 😉



class BearerTokenCredentialPolicy(_BearerTokenCredentialPolicyBase, SansIOHTTPPolicy):
class BearerTokenCredentialPolicy(_BearerTokenCredentialPolicyBase, SansIOHTTPPolicy, HTTPPolicy):
Copy link
Member

@xiangyan99 xiangyan99 May 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the pipeline will call on_request or send or both?

Do we have a design for this scenario? @annatisch

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After #16726, the pipeline will call this policy's send method (instead of _SansIOHTTPPolicyRunner.send). Another option is for this policy not to inherit SansIOHTTPPolicy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an "AvecIOHTTPPolicy" (as opposed to Sans), I would remove the inheritance from SansIOHTTPPolicy and derive from the "correct" base class. I think that your implementation can call self.on_request and self.on_response to make sure they are called in a very similar fashion as before in order to handle any cases where someone has extended/derived from the policy, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have done. The extended policy follows _SansIOHTTPPolicyRunner's calling pattern such that it calls a subclass's on_* as the runner would.

@chlowell chlowell marked this pull request as ready for review May 17, 2021 15:24
@chlowell chlowell requested a review from xiangyan99 May 20, 2021 18:23


class BearerTokenCredentialPolicy(_BearerTokenCredentialPolicyBase, SansIOHTTPPolicy):
class BearerTokenCredentialPolicy(_BearerTokenCredentialPolicyBase, HTTPPolicy):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we planned to modify

if isinstance(policy, SansIOHTTPPolicy):

to check hasattibute('on_request'), will that change conflict with this one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's #16726. No conflict with this change, and this change doesn't require that PR.

@chlowell chlowell requested a review from xiangyan99 May 24, 2021 15:44
:param ~azure.core.pipeline.PipelineRequest request: the request
"""
self._enforce_https(request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you think about moving _enforce_https into shared utils?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense the next time another policy needs it. Do we want the key and SAS policies to enforce HTTPS as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked this because I saw ACR also used it. :)

Copy link
Member

@xiangyan99 xiangyan99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chlowell chlowell merged commit ec9d1dd into Azure:master May 24, 2021
@chlowell chlowell deleted the cae-core branch May 24, 2021 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants